local joy__luanfeng = fk.CreateSkill {

  name = "joy__luanfeng",

  tags = { Skill.Limited, },

}



joy__luanfeng:addEffect(fk.EnterDying, {
  name = "joy__luanfeng",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(joy__luanfeng.name) and target.maxHp >= player.maxHp and target.dying
    and player:usedSkillTimes(joy__luanfeng.name, Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, joy__luanfeng.name, nil, "#joy__luanfeng-invoke:"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:recover {
      who = target,
      num = 3 - target.hp,
      recoverBy = player,
      skillName = joy__luanfeng.name,
    }
    local targets = {player}
    table.insertIfNeed(targets, target)
    for _, p in ipairs(targets) do
      if not p.dead then
        local slots = table.simpleClone(p.sealedSlots)
        table.removeOne(slots, Player.JudgeSlot)
        if #slots > 0 then
          room:resumePlayerArea(p, slots)
        end
      end
    end
    if not target.dead then
      local n = 6 - target:getHandcardNum()
      if n > 0 then
        target:drawCards(n, joy__luanfeng.name)
      end
    end
    if player.dead then return end
    room:setPlayerMark(player, "joy__youlong_levelup", 1)
    room:setPlayerMark(player, "@$joy__youlong", 0)
  end,
})

return joy__luanfeng